<?php
$txt=file_get_contents('php://input');
logfile($txt,'nuomi_resend_ewm_log.txt');

function logfile($txt,$path){
	$fp = fopen($path,"a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}

$s1=new SoapClient("http://open.12301.cc/openService/MXSE.wsdl",array('encoding' =>'UTF-8','cache_wsdl' => 0));
$ac='123545'; //百度糯米接口账号
$pw='fa23a74898ad0ca49b6a9ae82e9b3fb8';

parse_str($txt,$date); //转换数据
//json_decode

$custId = '123545'; //二维码商帐号
$p_encode = '123545'; //二维码商密钥
$time = $date['time']; //获取时间戳
$encode = md5($p_encode.$time.$custId); //加密签名

if($date['encode'] == $encode) //判断签名是否相等
{
	$orderId = $date['orderId'];
	$thirdOrderId =$date['thirdOrderId'];
	$thirdTicketId =$date['thirdTicketId'];
	$arr= array();
	$cancel_array = array("ac"=>$ac,"pw"=>$pw,"in0"=>$orderId);
	
	//这里是重发短信程序
	$xml = $s1->__soapCall("reSend_SMS_Global_PL",$cancel_array);
	$result=simpleXML_load_string($xml);
	//throw new Exception("Value must be 1 or below");
	$str= array();
	try
 	{
	 	if ($result->Rec->UUerrorcode){
		$txt_json=json_encode($cancel_array);
		$txt_json.='|'.$result->Rec->UUerrorcode;
		err($txt_json,'nm_debug.txt');
		echo '{"msg":"failed", "data":"resend failed"}';
/*		$str["msg"] = "failed";
		$str["data"] = "resend failed";
		echo json_encode($str);
*/		throw new Exception(json_encode('{"msg":"failed", "data":"resend failed"}'));
		
			
		}else{
		//成功
/*			$str["msg"] = "success";
			$str["data"] = "resend success";
			echo json_encode($str);
*/			echo '{"msg":"success", "data":"resend success"}';
			}
	 }
	catch (Exception $e)
	 {
	 echo $e->errorMessage();
	 //echo '{"msg":"failed", "data":{"resend failed"}}';
	 }
		
}

function err($txt,$path){
	$fp = fopen($path,"a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}

?>